/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package CONTROLLER;

import BUS.*;
import java.util.*;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Controller;

/**
 * 
 * @author nhlvu07db373
 */
@Controller
public class NguoidungController {

    private NguoidungBUS ndBUS;
    private BannickBUS bnBUS;
    private TinhtrangnguoidungBUS ttndBUS;

    //Xử lý hiển thị danh sách người dùng
    @RequestMapping(value = "/quanlinguoidung")
    public ModelAndView nguoidungShow(HttpServletRequest request, HttpServletResponse response) throws Exception {
        response.setContentType("text/html;charset=UTF-8");
        request.setCharacterEncoding("UTF-8");
        Map<String, Object> mv = new HashMap<String, Object>();
        //Do something...
        try {
            List lstND = ndBUS.dsNguoidungAll();
            List lstTTND = ttndBUS.dsTinhtrangnguoidungAll();
            mv.put("lstND", lstND);
            mv.put("lstTTND", lstTTND);
        } catch (Exception ex) {
            System.err.print(ex);
        }
        return new ModelAndView("quanlinguoidungview", mv);
    }
    //Xử lý bannick

    @RequestMapping(value = "/bannick",method= RequestMethod.GET)
    public ModelAndView bannickNguoidungAction(HttpServletRequest request, HttpServletResponse response) throws Exception {
        response.setContentType("text/html;charset=UTF-8");
        request.setCharacterEncoding("UTF-8");
        Map<String, Object> mv = new HashMap<String, Object>();
        //Do something...
        try {
            String maND = request.getParameter("MaND");
            ndBUS.capnhattinhtrangNguoidung(maND, 1);
            bnBUS.saveBannick(maND);
            List lstND = ndBUS.dsNguoidungAll();
            List lstTTND = ttndBUS.dsTinhtrangnguoidungAll();
            mv.put("lstND", lstND);
            mv.put("lstTTND", lstTTND);
        } catch (Exception ex) {
            System.err.print(ex);
        }
        return new ModelAndView("quanlinguoidungview", mv);
    }
    //Xử lý tiep nhan gian hang moi

    @RequestMapping(value = "/xoanick",method= RequestMethod.GET)
    public ModelAndView xoanickNguoidungAction(HttpServletRequest request, HttpServletResponse response) throws Exception {
        response.setContentType("text/html;charset=UTF-8");
        request.setCharacterEncoding("UTF-8");
        Map<String, Object> mv = new HashMap<String, Object>();
        //Do something...
        try {
            String maND = request.getParameter("MaND");
            ndBUS.capnhattinhtrangNguoidung(maND, 3);
            List lstND = ndBUS.dsNguoidungAll();
            List lstTTND = ttndBUS.dsTinhtrangnguoidungAll();
            mv.put("lstND", lstND);
            mv.put("lstTTND", lstTTND);
        } catch (Exception ex) {
            System.err.print(ex);
        }
        return new ModelAndView("quanlinguoidungview", mv);
    }

    @RequestMapping(value = "/khoiphucnick", method= RequestMethod.GET)
    public ModelAndView khoiphucnickAction(HttpServletRequest request, HttpServletResponse response) throws Exception {
        response.setContentType("text/html;charset=UTF-8");
        request.setCharacterEncoding("UTF-8");
        Map<String, Object> mv = new HashMap<String, Object>();
        //Do something...
        try {
            String maND = request.getParameter("MaND");
            ndBUS.capnhattinhtrangNguoidung(maND, 2);
            List lstND = ndBUS.dsNguoidungAll();
            List lstTTND = ttndBUS.dsTinhtrangnguoidungAll();
            mv.put("lstND", lstND);
            mv.put("lstTTND", lstTTND);
        } catch (Exception ex) {
            System.err.print(ex);
        }
        return new ModelAndView("quanlinguoidungview", mv);
    }

    /**
     * @param ndBUS the ndBUS to set
     */
    @Autowired
    public void setNdBUS(NguoidungBUS ndBUS) {
        this.ndBUS = ndBUS;
    }

    /**
     * @param bnBUS the bnBUS to set
     */
    @Autowired
    public void setBnBUS(BannickBUS bnBUS) {
        this.bnBUS = bnBUS;
    }

    /**
     * @param ttndBUS the ttndBUS to set
     */
    @Autowired
    public void setTtndBUS(TinhtrangnguoidungBUS ttndBUS) {
        this.ttndBUS = ttndBUS;
    }
}
